package com.pipodi.itasamobile.utils;

import java.util.List;

import org.apache.http.cookie.Cookie;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.pipodi.itasamobile.connections.Connection;
import com.pipodi.itasamobile.connections.Constants;

public class LoginVariables {
	
	public static String currentUsername;
	public static String currentPassword;
	public static String userAuthCode;
	public static boolean logged = false;
	public static List<Cookie> loginCookies;
	
	public static void getAuthCode(String username, String password){
		LoginVariables.currentPassword = password;
		LoginVariables.currentUsername = username;
		Document doc = Connection.connectToAPIUrl("https://api.italiansubs.net/api/rest/users/login?username=" + username + "&password=" + password + "&apikey=" + Constants.APIKey);
		NodeList nodeList = doc.getElementsByTagName("user");
		Node authCodeNode = nodeList.item(0);
		Element authCodeElement = (Element) authCodeNode;
		LoginVariables.userAuthCode = authCodeElement.getElementsByTagName("authcode").item(0).getTextContent();
	}

}
